home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 2.iso / Utils / UNIX / UNZIP520 / WINGUI / SIZEWNDW.C < prev    next >
C/C++ Source or Header  |  1996-03-03  |  5KB  |  148 lines

  1. /* sizewndw.c module of WizUnZip.
  2.  * Author: Robert A. Heath
  3.  * I, Robert Heath, place this source code module in the public domain.
  4.  *
  5.  * Modifications M. White 1995
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include "wingui\wizunzip.h"
  10.  
  11. #define MIN_LISTBOX_LINES 2
  12.  
  13. /* Call this when the window size changes or needs to change. */
  14. void SizeWindow(HWND hWnd, BOOL bOKtoMovehWnd)
  15. {
  16.     WORD wMinClientWidth;       /* minimum client width     */
  17.     int nListBoxHeight;         /* height of listbox in pix         */
  18.     WORD wVariableHeight;       /* no. variable pixels on client    */
  19.     WORD wVariableLines;            /* no. variable lines on client window */
  20.     WORD wMessageBoxHeight;     /* message box height in pixels     */
  21.     WORD wClientWidth, wClientHeight;       /* size of client area  */
  22.     RECT rectT;
  23.     int nCxBorder;
  24.     int nCyBorder;
  25.     int nCxVscroll; /* vertical scroll width */
  26.     int nCyHscroll; /* vertical scroll width */
  27.     int nCyCaption; /* caption height       */
  28.  
  29.     BtnMult = (float)BTNWIDTH; /* Reset multiplier to original setting */
  30.     BtnSeparator = 1;   /* Set distance between buttons back to 1 */
  31.     Width = (int)(BtnMult*dxChar);
  32.  
  33.     WinAssert(hWndMain);
  34.     GetClientRect(hWndMain, &rectT);
  35.     if (((Width * NumOfBtns) + NumOfBtns) > rectT.right)
  36.        {
  37.        while (BtnMult > MIN_BTN_WIDTH)
  38.           {
  39.           BtnMult = (float)(BtnMult - 0.1);
  40.           Width = (int)(BtnMult*dxChar);
  41.           if (((Width * NumOfBtns) + NumOfBtns) < rectT.right)
  42.              {
  43.              MoveButtons();
  44.              break;
  45.              }
  46.           }
  47.        }
  48.     else
  49.        {
  50.        MoveButtons();
  51.        }
  52.  
  53.     if (((Width * NumOfBtns) + NumOfBtns) > rectT.right)
  54.        {
  55.        BtnSeparator = 0;
  56.        MoveButtons();
  57.        }
  58.  
  59.     WinAssert(hWnd);
  60.     GetClientRect(hWnd, &rectT);
  61.     wClientWidth = (WORD)(rectT.right-rectT.left+1); /* x size of client area */
  62.     wClientHeight = (WORD)(rectT.bottom-rectT.top+1); /* y size of client area */
  63.     if (wWindowSelection == IDM_MAX_STATUS)
  64.        {
  65.        /* position the status window to fill entire client window   */
  66.        WinAssert(hWndStatus);
  67.        MoveWindow(hWndStatus, 0, (3 * dyChar),
  68.             wClientWidth, wClientHeight-(3*dyChar), TRUE);
  69.        cLinesMessageWin = (WORD)(wClientHeight / dyChar);
  70.        return;
  71.        }
  72.  
  73.     nCxBorder = GetSystemMetrics(SM_CXBORDER);
  74.     nCyBorder = GetSystemMetrics(SM_CYBORDER);
  75.     nCxVscroll = GetSystemMetrics(SM_CXVSCROLL);
  76.     nCyHscroll = GetSystemMetrics(SM_CYHSCROLL);
  77.     nCyCaption = GetSystemMetrics(SM_CYCAPTION);
  78.  
  79.     if (wClientHeight < (WORD)(11*dyChar))
  80.         wClientHeight = (WORD)(11*dyChar);
  81.  
  82.     /* List Box gets roughly 1/2 of lines left over on client
  83.      * window after subtracting fixed overhead for borders,
  84.      * horizontal scroll bar,
  85.      * button margin spacing, header, and trailer lines.
  86.      * unless the status window is minimized
  87.      */
  88.     wVariableHeight =  (WORD)(wClientHeight - (2 * nCyBorder) - (6 * dyChar));
  89.     if (wWindowSelection != IDM_MAX_LISTBOX)
  90.         wVariableHeight -= (WORD)(nCyHscroll + nCyCaption + (2*nCyBorder) + dyChar);
  91.     wVariableLines = (WORD)(wVariableHeight / dyChar);
  92.     cListBoxLines =  (WORD)((wWindowSelection == IDM_MAX_LISTBOX) ?
  93.                wVariableLines : wVariableLines / 2);
  94.  
  95.     if (cListBoxLines < MIN_LISTBOX_LINES)
  96.         cListBoxLines = MIN_LISTBOX_LINES;
  97.  
  98.     cLinesMessageWin = (WORD)(wVariableLines - cListBoxLines); /* vis. msg. wnd lines */
  99.  
  100.     wMinClientWidth = (WORD)
  101.        ((!uf.fFormatLong ? MIN_SHORT_FORMAT_CHARS : MIN_LONG_FORMAT_CHARS) * dxChar +
  102.                       nCxVscroll + 2 * nCxBorder);
  103.  
  104.     /* if we moved the hWnd from WM_SIZE, we'd probably get into
  105.      * a nasty, tight loop since this generates a WM_SIZE.
  106.      */
  107.     if (bOKtoMovehWnd && (wClientWidth < wMinClientWidth))
  108.        {
  109.        wClientWidth = wMinClientWidth;
  110.        GetWindowRect(hWnd, &rectT);
  111.        WinAssert(hWnd);
  112.        MoveWindow(hWnd, rectT.left, rectT.top,
  113.           wClientWidth + (2*GetSystemMetrics(SM_CXFRAME)),
  114.           wClientHeight, TRUE);
  115.        }
  116.  
  117.     WinAssert(hWndButtonBar);
  118.     MoveWindow(hWndButtonBar,
  119.          0, 1,
  120.          wClientWidth,28,
  121.          TRUE);
  122.     /*
  123.      * Position the "display" listbox.
  124.      */
  125.     nListBoxHeight = (cListBoxLines * dyChar) + (2 * nCyBorder) +
  126.       (int)(1.5 * dyChar);
  127.  
  128.        WinAssert(hWndList);
  129.        MoveWindow(hWndList,
  130.             0, dyChar+ (2 * dyChar), /* drop display listbox two lines down */
  131.             wClientWidth,nListBoxHeight + (2*dyChar),
  132.             TRUE);
  133.  
  134.     /* Position the status (Message) window.
  135.      * The Message windows is positioned relative to the bottom
  136.      * of the client area rather than relative to the top of the client.
  137.      */
  138.     wMessageBoxHeight = (WORD)(wVariableHeight - nListBoxHeight +
  139.                         2 * nCyBorder +
  140.                         nCyHscroll + nCyCaption);
  141.  
  142.     WinAssert(hWndStatus);
  143.     MoveWindow(hWndStatus,
  144.             0, wClientHeight - wMessageBoxHeight,
  145.             wClientWidth, wMessageBoxHeight,
  146.             TRUE);
  147. }
  148.